#include <QJsonArray>
#include <QJsonObject>
#include <QList>
#include <QString>

#ifndef ROLE_H
#define ROLE_H

#endif // ROLE_H

class Role{
public:
    QString createBy;
    QString createTime;
    QString updateBy;
    QString updateTime;
    QString remark;
    int roleId;
    QString roleName;
    QString roleKey;
    int roleSort;
    QString dataScope;
    bool menuCheckStrictly;
    bool deptCheckStrictly;
    QString status;
    int delFlag;
    bool flag;
    QList<int> menuIds;
    QList<int> deptIds;
    QStringList permissions;
    bool admin;

    QJsonObject toJsonObject(){
        QJsonObject obj;
        obj.insert("createBy",createBy);
        obj.insert("createTime",createTime);
        obj.insert("updateBy",updateBy);
        obj.insert("updateTime",updateTime);
        obj.insert("remark",remark);
        obj.insert("roleId",roleId);
        obj.insert("roleName",roleName);
        obj.insert("roleKey",roleKey);
        obj.insert("roleSort",roleSort);
        obj.insert("dataScope",dataScope);
        obj.insert("menuCheckStrictly",menuCheckStrictly);
        obj.insert("deptCheckStrictly",deptCheckStrictly);
        obj.insert("flag",flag);
        obj.insert("status",status);
        obj.insert("delFlag",delFlag);
        obj.insert("admin",admin);
        obj.insert("permissions",QJsonArray::fromStringList(permissions));
        QJsonArray jsonArraymenuIds;
        for(int i = 0;i< menuIds.size();i++){
            jsonArraymenuIds.append(menuIds.at(i));
        }
        obj.insert("menuIds",jsonArraymenuIds);
        QJsonArray jsonArraydeptIds;
        for(int i = 0;i< deptIds.size();i++){
            jsonArraydeptIds.append(deptIds.at(i));
        }
        obj.insert("deptIds",jsonArraydeptIds);
        return obj;
    }
    static Role toRole(const QJsonObject& json) {
        Role role;
        role.createBy = json["createBy"].toString();
        role.createTime = json["createTime"].toString();
        role.updateBy = json["updateBy"].toString();
        role.updateTime = json["updateTime"].toString();
        role.remark = json["remark"].toString();
        role.roleId = json["roleId"].toInt();
        role.roleName = json["roleName"].toString();
        role.roleKey = json["roleKey"].toString();
        role.roleSort = json["roleSort"].toInt();
        role.dataScope = json["dataScope"].toString();
        role.menuCheckStrictly = json["menuCheckStrictly"].toBool();
        role.deptCheckStrictly = json["deptCheckStrictly"].toBool();
        role.status = json["status"].toString();
        role.delFlag = json["delFlag"].toInt();
        role.flag = json["flag"].toBool();
        role.admin = json["admin"].toBool();

        // 解析menuIds
        QJsonArray menuIdsArray = json["menuIds"].toArray();
        for (const QJsonValue& value : menuIdsArray) {
            role.menuIds.append(value.toInt());
        }

        // 解析deptIds
        QJsonArray deptIdsArray = json["deptIds"].toArray();
        for (const QJsonValue& value : deptIdsArray) {
            role.deptIds.append(value.toInt());
        }

        // 解析permissions
        QJsonArray permissionsArray = json["permissions"].toArray();
        for (const QJsonValue& value : permissionsArray) {
            role.permissions.append(value.toString());
        }

        return role;
    }
};
